<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .box1 {
        width: 100px;
        height: 100px;
        background-color: pink;
        display: none;
        text-align: center;
      }
      .box2 {
        width: 100px;
        height: 100px;
        display: none;
        text-align: center;
        background-color: gray;
      }
      .box3 {
        width: 100px;
        height: 100px;
        text-align: center;
        display: none;
        background-color: greenyellow;
      }
    </style>
  </head>
  <body>
    <button>按钮一</button>
    <button>按钮二</button>
    <button>按钮三</button>

    <div class="box1">1</div>
    <div class="box2">2</div>
    <div class="box3">3</div>

    <script>
      let btn = document.querySelectorAll("button");
      let div = document.querySelectorAll("div");
      for (let i = 0; i < btn.length; i++) {
        // console.log(btn[i]);
        btn[i].onclick = function () {
          for (let j = 0; j < div.length; j++) {
            div[j].style.display = "none";
            div[i].style.display = "block";
            console.log(i);
            console.log(j);
          }
        };
      }
    </script>
  </body>
</html>
